//index.js
//获取应用实例
import util from '../../../utils/util.js';
let app = getApp()
Page({
	data:{
		/*
			bannerSrc  banner数据
			*/
			bannerSrc: [],
			tabBtn:0,
			tabActive:0,
			navStatus:0,
			tabContentThree:[],
			tabContentPeople:[],
			navMain:[]
		},


	//生命周期函数--监听页面加载
	onLoad: function () {
		wx.showLoading({
			title: '加载中...'
		});
		this.getUserInfo();
		this.getBanner();//获取banner
		// this.getShopSiteInfo();
		// this.getNotices();
		this.getPorducts();
	},

  
	// 个人信息
	getUserInfo() {
		var self = this;
		var userInfo = wx.getStorageSync('user');
		// 判断是否登陆
		if (userInfo.is_completed) {
		  // 获取用户信息
		  if (userInfo.avatar === null) {
		  	userInfo.avatar = "/images/default-avatar.png";
		  }
		  var photo = userInfo.avatar,
		  name = userInfo.username,
		  level = userInfo.rank,
		  user = {};
		  user.avatarUrl = photo;
		  user.nickName = name;
		  user.level = level;
		  self.setData({
		  	userInfo: user
		  });
		}
	},


	// 移动端 Banner
	getBanner() {
		let self = this
	    util.request(util.apiUrl + 'xcx.pin.banner', 'POST', {
	    	id:[116]
	    }).then(res => {
	    	console.log('banner_Data', res.data[116])
	    }).catch(err => {
	    	let arr = err.data[116].reverse()
	    	self.setData({
	    		'bannerSrc': arr
	    	})
	    });
	},

	// 首页展示产品
  // ecapi.home.product.list
  getPorducts() {
  	let self = this
  	wx.request({
  		url: util.apiUrl + 'xcx.pin.pintuan', 
  		data: {
  			id:60
  		},
  		header: {
	      'content-type': 'application/json' // 默认值
	  },
	  method:'POST',
	  success: function(res) {
	  	self.setData({
	  		tabContentThree:res.data.data['三人拼团'],
	  		tabContentPeople:res.data.data['人人拼']
	  	})
	  	wx.hideLoading();
	  }
	})


  		// util.request(util.apiUrl + 'xcx.pin.pintuan', 'POST', {
	   //  	id:60
	   //  }).then(res => {
	   //  	console.log('首页展示产品', res)
	   //  }).catch(err => {
	   //  	console.log('首页展示产品',err)
		  // 	// self.setData({
		  // 	// 	tabContentThree:err.data.data['三人拼团'],
		  // 	// 	tabContentPeople:err.data.data['人人拼']
		  // 	// })
		  // 	wx.hideLoading();
	   //  });




  },

	//切换选项卡  三人拼  人人拼
	tabClassName(Param){
    console.log('tabClassName')
		let bannerStatus = Param.target.dataset.b_status
		bannerStatus = (bannerStatus == 0)? 1: 0;
		this.setData({
			tabBtn:bannerStatus,
			tabActive:bannerStatus
		})
	},
	//跳转我的页面
	jumpTo_mePage(){
		wx.redirectTo({
			url: '../me/me'
		})
	},

  onShareAppMessage: function (res) {
    let id = this.data.id
    let user = wx.getStorageSync('user')
    let pid = this.data.pidNow
    let userName = user.nickname
    if (res.from === 'button') {
    }
    // 来自页面内转发按钮
    return {
      title: '您的好友正在这里买东西，邀请您一起享优惠！',
      path: '/pages/pin_J/index/index',
      imageUrl: 'https://www.zhenlvw.com/images/xiao/share2.jpg',
      success: (res) => {
        console.log("转发成功", res);
      },
      fail: (res) => {
        console.log("转发失败", res);
      }
    }
  }

})
